Skip to content

feat: record the event types a store holds and hold what newer code wrote (SCHEMA_AHEAD) - #234

Closed
benatespina wants to merge 13 commits into
mainfrom
feat/event-catalogue
Closed

benatespina wants to merge 13 commits into
mainfrom
feat/event-catalogue

Conversation

@benatespina

@benatespina benatespina commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

First of two stacked changes for schema evolution; feat/event-lineage (formerly and retired) builds on this one.

What changes

  • Catalogue. EventStore.types() lists every (aggregateType, type, schemaVersion) of a committed event. append records the ones it has not met in its own transaction, in a new bounda_event_types table (SQLite in core, PostgreSQL, the Durable Object through createSqliteAdapter) and in the memory store. A set shared by a storage's stores, filled by types(), keeps a booted app from writing rows it already has; what a transaction records counts only once it commits. Shared SQL pieces live in core/adapter/sql/event-types.ts.
  • Boot check. checkStoredTypes (kernel/aggregate/stored-types.ts) runs in assembleApp, right after the storage opens and the aggregates are built, and in rebuildReadModel. A store holding an event type, aggregate or process the code no longer has, or a schema version past the one it knows, refuses with one ConfigurationError naming each.
  • SchemaAheadError (SCHEMA_AHEAD), transient, for what newer code wrote while a deploy rolls out: a future schema version, or an unknown type the catalogue records (without a row it stays a ConfigurationError).
    • load, readOne and readByPerson throw it; readAll returns the events before the first unreadable one and throws only when it comes first.
    • A subscriber's read that throws it is a failed delivery at the event's position: back-off, getLag().failing, nothing dead-lettered.
    • A policy or process reaction fails its claim and holds with its back-off, and never gives up on this code. The inbox's tryClaim already counts the attempt, so it is counted as today.
    • The scheduler worker defers the entry by runtime.dispatcher.backoff.baseDelay without an attempt.
    • A dead-letter retry rejects with it and the letter stays failed.
  • A non-system event of an aggregate the code does not have is now refused like an unknown type instead of passed through, so an old instance never moves a checkpoint past a new aggregate's events.
  • failure() (React Router) and createWorker (Cloudflare) answer SCHEMA_AHEAD with a 503.

Docs

reference/errors (SCHEMA_AHEAD, INVALID_CONFIGURATION at boot, HTTP table), guides/deployment ("Deploying a change to events"), adapters (the bounda_event_types row), guides/changing-events and guides/react-router. One minor changeset for core, postgresql, cloudflare and react-router.

Checks

  • pnpm check green with Docker running (PostgreSQL suite included): 2467 tests.
  • Stryker on the touched files of core and postgresql; the new code's survivors were killed with new tests except one equivalent mutant (event-types.ts, the initial array of a pending set). The rest are older.
  • New contract cases in eventStoreContract and storageTransactionContract, which also run inside workerd.

EventStore gains types(): every (aggregateType, type, schemaVersion) of a
committed event, recorded by append in its own transaction in a new
bounda_event_types table on SQLite, PostgreSQL and the Durable Object, and
in the memory store. A set shared by a storage's stores, filled by types(),
keeps a booted app from writing rows it already has; a transaction's types
count only once it commits.

Boot and rebuildReadModel refuse a store holding events the code cannot
read (an event type, aggregate or process it no longer has, or a schema
version past the one it knows) with one ConfigurationError naming each.

What newer code wrote while a deploy rolls out is now the transient
SchemaAheadError (SCHEMA_AHEAD): load, readOne and readByPerson throw it,
readAll hands out the events before it and throws only when it comes first,
a subscriber backs off before it, a reaction holds it without ever giving
up, a scheduled command is deferred without an attempt, and a dead-letter
retry rejects with it.
# Conflicts:
#	docs/src/content/docs/adapters/index.mdx
# Conflicts:
#	packages/core/src/kernel/app.ts
#	packages/core/src/kernel/read-model/rebuild.ts
# Conflicts:
#	docs/src/content/docs/adapters/index.mdx
#	packages/core/src/adapter/sql/index.ts
#	packages/core/src/adapter/sqlite/adapter.ts
#	packages/postgresql/src/index.ts
# Conflicts:
#	packages/core/src/kernel/personal-data/export.test.ts
…atalogue

# Conflicts:
#	packages/core/src/adapter/sqlite/adapter.ts
#	packages/core/src/adapter/sqlite/event-store.ts
#	packages/core/src/adapter/sqlite/sqlite.test.ts
#	packages/core/src/adapter/testing/event-store.contract.ts
#	packages/core/src/kernel/read-model/rebuild.test.ts
#	packages/core/src/memory/event-store.ts
#	packages/postgresql/src/event-store.ts
#	packages/postgresql/src/postgresql.test.ts
…atalogue

# Conflicts:
#	docs/src/content/docs/adapters/index.mdx
…atalogue

# Conflicts:
#	docs/src/content/docs/adapters/index.mdx
#	docs/src/content/docs/reference/errors.md
#	packages/core/src/kernel/app.ts
#	packages/core/src/kernel/personal-data/export.test.ts
#	packages/core/src/kernel/read-model/rebuild.ts
…atalogue

# Conflicts:
#	packages/core/src/adapter/index.ts
#	packages/core/src/adapter/sqlite/event-store.ts
#	packages/core/src/adapter/staged-event-store.ts
#	packages/core/src/adapter/storage/event-store.ts
#	packages/core/src/adapter/testing/event-store.contract.ts
#	packages/core/src/kernel/aggregate/upcasting.test.ts
#	packages/core/src/kernel/aggregate/upcasting.ts
#	packages/core/src/kernel/personal-data/event-store.ts
#	packages/core/src/kernel/personal-data/ledger-append.ts
#	packages/core/src/memory/event-store.ts
#	packages/postgresql/src/event-store.ts
…atalogue

# Conflicts:
#	packages/core/src/kernel/personal-data/export.test.ts
@benatespina

Copy link
Copy Markdown
Member Author

Superseded by #383, rebuilt on the current main.

@benatespina benatespina closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant